﻿/*
 * Author:feitianxinhong
 * CreateDate:2013-08-19
 * CopyRight:【Tyingsoft】Twilight Software Development Studio ©2013 
 * Description:Twi.Msg base on HubSpot messenger
 * Require:messenger-1.3.5
 * ------------------------------------------------------------------
 *  编号    版本号      作者              修改日期        修改内容
 * ------------------------------------------------------------------
 *   1      1.0.0       feitianxinhong    2013-8-19       根据之前的Twi使用Extjs框架改成使用jquery的简化版
 *   2      1.0.1       feitianxinhong    2015-01-17      将自动加载messenger-1.3.5去掉
 * ------------------------------------------------------------------
 */

(function () {
    var global = this;
    if (typeof Twi === 'undefined') {
        global.Twi = {};
    }
    Twi.global = global;
    //if ($('body').length == 0) {
    //    document.write('<link href="/Framework/messenger-1.3.5/css/messenger.css" rel="stylesheet" type="text/css" />');
    //    document.write('<link href="/Framework/messenger-1.3.5/css/messenger-theme-future.css" rel="stylesheet" type="text/css" />');
    //    document.write('<script src="/Framework/messenger-1.3.5/js/messenger.min.js" type="text/javascript"></script>');
    //}
    //else {
    //    $("body").append('<link href="/Framework/messenger-1.3.5/css/messenger.css" rel="stylesheet" type="text/css" />');
    //    $("body").append('<link href="/Framework/messenger-1.3.5/css/messenger-theme-future.css" rel="stylesheet" type="text/css" />');
    //    $("body").append('<script src="/Framework/messenger-1.3.5/js/messenger.min.js" type="text/javascript"></script>');
    //}
})();

Twi.Msg = {
    Info: function (config) {
        if (typeof config == "string") config = { message: config };
        config = config || {};
        var msgConfig = {};
        Twi.apply(msgConfig,config,{
            message: '操作成功',
            //hideAfter: 3, //3秒后自动关闭
            showCloseButton: true
        });
        $.globalMessenger().post(msgConfig);
    }
    , Error: function (config) {
        if (typeof config == "string") config = { message: config };
        config = config || {};
        var msgConfig = {};
        Twi.apply(msgConfig, config, {
            message: '操作失败',
            type: 'error',
            //hideAfter: 3, //3秒后自动关闭
            showCloseButton: true
        });
        $.globalMessenger().post(msgConfig);
    }
    , Comfirm: function (handler, msg) {
        msg = msg || "执行后数据不能恢复，你确定要执行吗？";
        var messenger;
        messenger = $.globalMessenger().post({
            message: msg,
            actions: {
                retry: {
                    label: '是',
                    action: function () {
                        if (typeof handler == "function") {
                            handler();
                        }
                    }
                },
                cancel: {
                    label: '否',
                    action: function () {
                        return messenger.cancel();
                    }
                }
            }
        });
    }
} //end Twi.Msg